using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The LocationTableManager class is responsible for managing BO.LocationTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class LocationTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all LocationTable objects in the database.
        /// </summary>
        /// <returns>A list with all LocationTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static LocationTableList GetList(int SchoolKey)
        {
            return LocationTableDB.GetList(SchoolKey);
        }

        /// <summary>
        /// Gets a single LocationTable from the database without its data.
        /// </summary>
        /// <param name="locationKey">The LocationKey of the LocationTable in the database.</param>
        /// <returns>A LocationTable object when the LocationKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static LocationTable GetItem(int locationKey)
        {
            return GetItem(locationKey, false);
        }

        /// <summary>
        /// Gets a single LocationTable from the database.
        /// </summary>
        /// <param name="locationKey">The LocationKey of the LocationTable in the database.</param>
        /// <param name="getLocationTableRecords">Determines whether to load all associated LocationTable records as well.</param>
        /// <returns>
        /// A LocationTable object when the LocationKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static LocationTable GetItem(int locationKey, bool getLocationTableRecords)
        {
            LocationTable myLocationTable = LocationTableDB.GetItem(locationKey);
            //if (myLocationTable != null && getLocationTableRecords)
            //{
            //    myLocationTable.classRoomLocationTables = ClassRoomLocationTableDB.GetListByLocationKey(locationKey);
            //}
            return myLocationTable;
        }

        /// <summary>
        /// Saves a LocationTable in the database.
        /// </summary>
        /// <param name="myLocationTable">The LocationTable instance to save.</param>
        /// <returns>The new LocationKey if the LocationTable is new in the database or the existing LocationKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(LocationTable myLocationTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int locationTableLocationKey = LocationTableDB.Save(myLocationTable);
                //foreach (ClassRoomLocationTable myClassRoomLocationTable in myLocationTable.classRoomLocationTables)
                //{
                //    myClassRoomLocationTable.LocationKey = locationTableLocationKey;
                //    ClassRoomLocationTableDB.Save(myClassRoomLocationTable);
                //}

                //  Assign the LocationTable its new (or existing LocationKey).
                myLocationTable.LocationKey = locationTableLocationKey;

                myTransactionScope.Complete();

                return locationTableLocationKey;
            }
        }

        /// <summary>
        /// Deletes a LocationTable from the database.
        /// </summary>
        /// <param name="myLocationTable">The LocationTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        //[DataObjectMethod(DataObjectMethodType.Delete, true)]
        //public static bool Delete(LocationTable myLocationTable)
        //{
        //    return LocationTableDB.Delete(myLocationTable.LocationKey);
        //}

        /// <summary>
        /// Deletes a LocationTable from the database.
        /// </summary>
        /// <param name="myLocationTable">The LocationTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public static bool Delete(int LocationKey, out string errorMessage)
        {
            return LocationTableDB.Delete(LocationKey, out errorMessage);
        }

        #endregion

    }

}
